Name :Addition and subtraction counts

Symbol:CTUD

Illustrate:

    You can use the Add and Subtract Count command to increment and decrement the counter value of the output CV. If the signal status of the input CU changes from "0" to "1" (signal rising edge), the current counter value is added to 1 and stored in the output CV. If the signal status of the input CD changes from "0" to "1" (signal rising edge), the counter value of the output CV is minus 1. If, during a program cycle, both the input CU and the CD have a rising edge, the current counter value of the output CV remains unchanged.
    The counter value can be incremented until it reaches the upper limit of the specified data type at the output CV. Once the upper limit is reached, the counter value is no longer incremented, even if there is a rising edge of the signal. Once the lower limit of the specified data type is reached, the counter value is no longer decremented.
    When the signal status of input LD1 changes to "1", the counter value of the output CV is set to the value of the parameter PV. As long as the signal status of input LD1 remains "1", the signal status of input CU and CD will not affect the instruction.
    When the signal status of input R1 changes to "1", the counter value is set to "0". As long as the signal status of input R1 remains "1", changes in the status of the input CU, CD, and LD signals will not affect the "add and subtract count" command.
    You can query the status of the plus counter in the QU output. If the current counter value is greater than or equal to the value of the parameter PV, the signal status of the output QU is set to "1". In all other cases, the signal status of the output QU is "0".
    You can query the status of the subtractive counter in the QD output. If the current counter value is less than or equal to "0", the signal status of the QD output will be set to "1". In all other cases, the signal status of the output QD is "0". 

Image:

Parameter:

Parameter Statement Type Description
CU Input BOOL
Add count inputs
CD Input BOOL
Subtract the count input
R1 Input BOOL
Reset input
LD1 Input BOOL
Load inputs
PV Input INT
In the case of output QU set value/LD = 1, the output CV is set value.
QU Output BOOL
Add the status of the counter
QD Output BOOL
Subtract the status of the counter
CV Output INT
The current counter value

Example:

LD:

ST:



Interpretation:

    If the signal status of the input "TagIn1" or "TagIn2" changes from "0" to "1" (signal rising edge), the "Add and Subtract Count" command is executed. When the signal rises on the input "TagIn1", the current counter value is added to 1 and stored in the output "TagCV". When the signal rises on the input "TagIn2", the counter value is minus 1 and stored in the output "TagCV". When the input CU has a rising edge of the signal, the counter value is incremented until it reaches the upper limit value of 32767. When the input CD has a rising edge of the signal, the counter value is decremented until it reaches the lower limit (INT=-32768).
    As long as the current counter value is greater than or equal to the value of the "TagPV" input, the signal status of the "TagQU" output is "1". In all other cases, the signal status of the output "TagQU" is "0".
    As long as the current counter value is less than or equal to 0, the signal status of the "TagQD" output is "1". In all other cases, the signal status of the output "TagQD" is "0".